﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameFramework;

namespace MYSTARFORCE
{
    /// <summary>
    /// 粒子特效逻辑
    /// </summary>
    public class Effect : Entity
    {
        [SerializeField]
        private EffectData m_EffectData = null;

        // 当前播放时间
        private float m_ElapseSeconds = 0f;

        protected override void OnShow(object userData)
        {
            base.OnShow(userData);

            m_EffectData = userData as EffectData;

            if(m_EffectData == null)
            {
                Log.Warning("Effect data is invalid");
                return;
            }

            m_ElapseSeconds = 0f;
        }

        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            m_ElapseSeconds += elapseSeconds;
            // 如果当前已播放时间超过了我们规定的播放时间，就把粒子效果隐藏了
            if(m_ElapseSeconds >= m_EffectData.KeepTime)
            {
                GameEntry.Entity.HideEntity(this);
            }
        }
    }
}